<?php

namespace app\admin\controller;
use app\admin\model\ScoreChargeModel;
use app\common\controller\AdminBaseController;
use think\Db;
/**
 *积分
 */
class ScoreChargeController extends AdminBaseController
{
 	protected $model;
 		
    protected function _initialize() {
        parent::_initialize();
        $this->model = new ScoreChargeModel();
    }
    /**
     * 积分变化列表
     * @author [longx] 
     */
    public function index( $page = 1){
        $list = $this->model->paginate(10);
         $list1=$this->model
                     ->table('long_mall_score_charge a,long_member b')                    
                     ->where('a.id=b.id')
                     ->select();                                                                              
        return $this->fetch('index', ['list1' => $list, 'list1' => $list1]);
      
    }
    /**
     *查询 
 */
    
    public function search(){
    	$map = [];
		$field = 'm.*,g.id,g.nick_name';		    	
    	if(request()->isPost()){
		 	$param = input('post.');		
			//用户名称
			if($param['nickname']){
				$map['g.nick_name'] = ['like', '%'.$param['nickname'].'%'];
			}				
			//创建时间
			if($param['createtime']&&$param['end_time']){
				$map['m.createtime'] = ['between time', [$param['createtime'],$param['end_time']]];
			}		
	 	}
		$dd=Db::name("mall_score_charge")->alias('m')->join('__MEMBER__ g','g.id=m.id')->field($field)->where($map)->paginate(10);
        return $this->fetch('index', ['list1' => $dd]);
    }
 
    /**
     * 
     *添加
     * @author [longx] 
     */
    public function add()
    {
        if(request()->isAjax()){
        	$param=input('post.');
			$param['add_time']=now_time();
			if ($this->model->allowField(true)->save($param) !== false) {
                    $this->success('添加成功', url('Goods/index'));
            } else {
                $this->error('添加失败');
            }
        }
        return $this->fetch();
    }


    /**
     * [edit 编辑]
     * @return [type] [description]
     * @author [longx]
     */
    public function edit($id)
    {
        if(request()->isAjax()){
            $param = input('post.');         
         	if ($this->model->allowField(true)->save($param,$id) !== false) {
                    $this->success('修改成功', url('Goods/index'));
            } else {
                $this->error('修改失败');
            }
        }
        $id = input('param.id');
        $this->assign('ad',$this->model->find($id));
        return $this->fetch();
    }



    /**
     * [del删除]
     * @author [longx] 
     */
    public function delete()
    {
        $id = input('param.id');
        if ($this->model->destroy($id)) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }
}